﻿using System.Data;
using System.Data.SqlClient;

namespace Adams.Public.DataAccess
{
    public static class Files
    {
        public static Adams.Shared.Entities.Files.File GetFile(Adams.Public.DataTransfer.Files.GetFileInput input)
        {
            var data = new Adams.Shared.Entities.Files.File();

            using (SqlDataReader dr = DB.RunDataReader(@"
SELECT F.*
FROM Files.Files F
WHERE Url = @Url
", CommandType.Text,
    DB.CreateParameter("@Url", input.Url)))
            {
                dr.Read();
                data.ID = dr["FileID"].DbInt();
                data.Url = dr["Url"].DbString();
                data.ContentType = dr["ContentType"].DbString();
                data.Size = dr["Size"].DbLong();
                data.LastModified = dr["LastModified"].DbDate();
                data.Content = (byte[])dr["Content"];
            }

            return data;
        }
    }
}
